cmake_minimum_required(VERSION 2.8)
project(learnco)

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -rdynamic -O0 -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-reorder -Wno-unused-function -Wno-builtin-macro-redefined")

find_package(Boost REQUIRED)
if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS})
endif()


# 添加头文件
include_directories(./learnco)
include_directories(./learnco/logger)
include_directories(./learnco/thread)
include_directories(./learnco/fiber)
include_directories(./learnco/scheduler)
include_directories(./learnco/iomanger)
include_directories(./learnco/timer)
include_directories(./learnco/hook)
include_directories(./learnco/http)
include_directories(./learnco/http/mongrel2)


# 单独编译库
set(LIB_LOG
    ./learnco/logger/log.cc
    )
add_library(learnLog SHARED ${LIB_LOG})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

set(LIB_UTIL
    ./learnco/util.cc
    )
add_library(learnUtil SHARED ${LIB_UTIL})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

set(LIB_THREAD
    ./learnco/thread/thread.cc
    )
add_library(learnThread SHARED ${LIB_THREAD})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

set(LIB_FIBER
    ./learnco/fiber/fiber.cc
    )
add_library(learnFiber SHARED ${LIB_FIBER})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

set(LIB_SCHEDULER
    ./learnco/scheduler/scheduler.cc
    )
add_library(learnSche SHARED ${LIB_SCHEDULER})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

set(LIB_IOMANGER
    ./learnco/iomanger/iomanger.cc
    )
add_library(learnIomgr SHARED ${LIB_IOMANGER})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

set(LIB_TIMER
    ./learnco/timer/timer.cc
    )
add_library(learnTimer SHARED ${LIB_TIMER})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

set(LIB_HOOK
    ./learnco/hook/hook.cc
    )
add_library(learnHook SHARED ${LIB_HOOK})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

set(LIB_Http
    ./learnco/http/http.cc
    )
add_library(LIB_Http SHARED ${LIB_Http})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)


#汇总编译成一个库 learnco
set(LIB_SRC
    ./learnco/logger/log.cc
	./learnco/util.cc
    ./learnco/thread/thread.cc
    ./learnco/fiber/fiber.cc
	./learnco/scheduler/scheduler.cc
	./learnco/iomanger/iomanger.cc
	./learnco/timer/timer.cc
	./learnco/hook/hook.cc
	./learnco/http/http.cc
	./learnco/http/mongrel2/ragel_output/http11_parser.cc
	./learnco/http/mongrel2/ragel_output/httpclient_parser.cc
    )
add_library(learnco SHARED ${LIB_SRC})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

#添加库
#dl dlsym
set(LIBS
	learnco
    pthread
	dl 
    )
message("LIBS:  ${LIBS}")



add_executable(test_log tests/test_log.cpp)
add_dependencies(test_log learnLog)
target_link_libraries(test_log ${LIBS})
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

add_executable(test_thread tests/test_thread.cpp)
add_dependencies(test_thread learnThread)
target_link_libraries(test_thread ${LIBS})
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

add_executable(test_fiber tests/test_fiber.cpp)
add_dependencies(test_fiber learnFiber)
target_link_libraries(test_fiber ${LIBS})
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

add_executable(test_scheduler tests/test_scheduler.cpp)
add_dependencies(test_scheduler learnSche)
target_link_libraries(test_scheduler ${LIBS})
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

add_executable(test_iomanger tests/test_iomanger.cpp)
add_dependencies(test_iomanger learnco)
target_link_libraries(test_iomanger ${LIBS})
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

add_executable(test_timer tests/test_timer.cpp)
add_dependencies(test_timer learnco)
target_link_libraries(test_timer ${LIBS})
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

add_executable(test_hook tests/test_hook.cpp)
add_dependencies(test_hook learnco)
target_link_libraries(test_hook ${LIBS})
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)


# add_executable(test_http tests/test_http.cpp)
# add_dependencies(test_http learnco)
# target_link_libraries(test_http ${LIBS})
# SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
